package com.bejoy.coolatin.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

/**
 * viewPager适配器
 * 
 * @author Savvy 2014.12.25
 */
public class CommonViewPaperAdapter extends PagerAdapter {
	private Context context = null;
	private ArrayList<View> arrayList = null;

	public CommonViewPaperAdapter(Context context, ArrayList<View> arrayList) {
		this.context = context;
		this.arrayList = arrayList;
		// System.out.println("!!!!!!!!!!!!!position"+arrayList.size());
	}

	@Override
	public Object instantiateItem(View container, int position) {
		// System.out.println("!!!!!!!!!!!!!position"+position+"��"+position%arrayList.size());
		if (position <= arrayList.size()) {
			((ViewPager) container).addView(arrayList.get(position
					% arrayList.size()));
			return arrayList.get(position % arrayList.size());
		} else {
			return arrayList.get(0);
		}
	}

	@Override
	public void destroyItem(View container, int position, Object object) {
		((ViewPager) container).removeView(arrayList.get(position
				% arrayList.size()));
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == arg1;
	}

	@Override
	public int getCount() {
		return arrayList.size();
	}

	@Override
	public void restoreState(Parcelable arg0, ClassLoader arg1) {
	}

	@Override
	public Parcelable saveState() {
		return null;
	}

	@Override
	public void startUpdate(View arg0) {
	}

}

